from datetime import datetime

from sqlalchemy import BigInteger, Column, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import Column, TEXT, Double, TIMESTAMP, VARCHAR
from sqlalchemy import PrimaryKeyConstraint

from sqlalchemy import Column, DateTime


# path = os.path.dirname(os.path.abspath(__file__))
# SQLALCHEMY_DATABASE_URL = "sqlite:///./geetest.db"
SQLALCHEMY_DATABASE_URL = 'postgresql+psycopg2://postgres:qiuwen123456@1.15.241.228:5433/data'
# SQLALCHEMY_DATABASE_URL = 'postgresql://dbuser_dba:DBUser.DBA@192.168.174.137:5432/data'
# SQLALCHEMY_DATABASE_URL = "mysql+pymysql://root:qiuwen123456@1.15.241.228/data"


engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
BaseModel = declarative_base()


class SensorData(BaseModel):
    __tablename__ = "sensor_data"  # 设置表明

    id = Column(BigInteger, primary_key=True)
    time = Column(TIMESTAMP)
    location = Column(TEXT, nullable=False, comment="位置")
    temperature = Column(Double, nullable=True)
    humidity = Column(Double, nullable=True)
    pressure = Column(Double, nullable=True)
    # PrimaryKeyConstraint("time", "location", name="time_location")
